app.service('propertyService',['$http','$q','utilService',function($http,$q,utilService){

    this.findShop = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/session'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.findMainPhone = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/get/phone'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.getMobilePhoneCode = function($scope,mobilePhone){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'system/user/getMobilePhoneCode',
            params:{mobilePhone:mobilePhone}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.confirm = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'withdrawal/add',
            data:$scope.data,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    this.findAll = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'bank/card'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    this.change = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'withdrawal/change',
            data:$scope.withdrawal,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    //查询订单对应的商品历史数据
    this.query = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domain + 'withdrawal/property/goods/history',
            params:{ordersDataHistoryId:$scope.goodsHistory.ordersDataHistoryId}
        }).then(function (response) {
            deferred.resolve(response.data);
        }, function (e) {
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    };
}]);